"""Image generation model."""

from __future__ import annotations

from sqlalchemy import Integer, String, Text, DateTime, func, Boolean, Column
from app.database import Base


class ImageGeneration(Base):
    __tablename__ = "image_generations"

    id = Column(Integer, primary_key=True, index=True)
    user_id = Column(Integer, index=True, nullable=False)
    prompt = Column(Text, nullable=False)
    style = Column(String(64), nullable=True)
    image_url = Column(String(512), nullable=False)
    user_subdir = Column(String(128), nullable=True, index=True)
    is_favorite = Column(Boolean, default=False, nullable=False)
    created_at = Column(
        DateTime(timezone=True), server_default=func.now(), nullable=False
    )

    def __repr__(self) -> str:  # pragma: no cover
        return f"<ImageGeneration id={self.id} user_id={self.user_id} prompt={self.prompt[:50]}...>"
